package cn.kgc.common.md5;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Util {

    public  static  String  encode(String code){
        StringBuilder re=new StringBuilder();
        try {
            MessageDigest digest= MessageDigest.getInstance("MD5");
            byte[] ny=digest.digest(code.getBytes());
            for (byte b : ny) {
                String hex= Integer.toHexString(b&0xff);
                if(hex.length()==1){
                    re.append("0"+hex);
                }else{
                    re.append(hex);
                }
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return re.toString();
    }
}
